const express = require('express');
const fileRoutes = require('./routes/fileRoutes');
const path = require('path');
const connectDB = require('./config/db');

const app = express();

// 连接数据库
connectDB();

app.use(express.json());  // 确保 Express 可以解析 JSON 请求体

app.use('/api', fileRoutes);

// 处理 React 应用的路由
app.use(express.static(path.join(__dirname, '../client/build')));
app.get('*', (req, res) => {
    res.sendFile(path.join(__dirname, '../client/build', 'index.html'));
});

const PORT = process.env.PORT || 5000;

app.listen(PORT, () => {
    console.log(`Server started on http://localhost:${PORT}`);
});